layui.use(['laydate','form','table','layer'], function(){
	var laydate = layui.laydate,form = layui.form,table = layui.table,layer = layui.layer;

	/*@营业员-员工信息*/
	sale_info = function(info)
	{
		html = '<thead>'+
				'	<tr>'+
				'		<th>员工编号</th>'+
				'		<th>姓名</th>'+
				'		<th>性别</th>'+
				'		<th>所属部门</th>'+
				'		<th>员工职位</th>'+
				'		<th>联系方式</th>'+
				'		<th>入职日期</th>'+
				'	</tr>'+
			  	'</thead>'+
			  	'<tbody>'+  	
				'	<tr>'+
				'		<td>'+info.admin_sn+'</td>'+
				'		<td>'+info.nkname+'</td>'+
				'		<td>'+info.sex_text+'</td>'+
				'		<td>'+info.shop_name+'</td>'+
				'		<td>'+info.g_title+'</td>'+
				'		<td>'+info.phone+'</td>'+
				'		<td>'+info.addtime+'</td>'+
	            '	</tr>'+
				'</tbody>';
		$('#staff-list').html(html)
	}
	/*@营业员-销售业绩*/
	sale_achi = function(achi)
	{
		html = '<thead>'+
				'	<tr>'+
				'		<th>销售总订单</th>'+
				'		<th>销售总额(元)</th>'+
				'		<th>销售总成本(元)</th>'+
				'		<th>退款总额(元)</th>'+
				'		<th>召回总额(元)</th>'+
				'		<th>销售总盈利(元)</th>'+
				'		<th>销售总提成(元)</th>'+
				'		<th>营业额总提成(元)</th>'+
				'		<th>操作(元)</th>'+
				'	</tr>'+
			  	'</thead>'+
			  	'<tbody>'+  	
				'	<tr>'+
				'		<td>'+achi.order_num+'</td>'+
				'		<td>'+achi.order_money+'</td>'+
				'		<td>'+achi.buying+'</td>'+
				'		<td>'+achi.refund_money+'</td>'+
				'		<td>'+achi.recal_money+'</td>'+
				'		<td>'+achi.sale+'</td>'+
				'		<td>'+achi.sale_bonus+'</td>'+
				'		<td>'+achi.turn_bonus+'</td>'+
				'		<td><div class="layui-btn" onclick="xadmin.parent_add_tab(\'员工销售记录\',\'/staff/order/index\')">员工销售记录</div></td>'+
	            '	</tr>'+
				'</tbody>';
		$('#achi-list').html(html)
	}
	/*@营业员-维修业绩*/
	sale_repair = function(repair)
	{
		html = '<thead>'+
				'	<tr>'+
				'		<th>维修总订单</th>'+
				'		<th>维修总额(元)</th>'+
				'		<th>维修总成本(元)</th>'+
				'		<th>维修总盈利(元)</th>'+
				'		<th>维修总提成(元)</th>'+
				'		<th>操作</th>'+
				'	</tr>'+
			  	'</thead>'+
			  	'<tbody>'+  	
				'	<tr>'+
				'		<td>'+repair.repair_num+'</td>'+
				'		<td>'+repair.repair_money+'</td>'+
				'		<td>'+repair.parts_money+'</td>'+
				'		<td>'+repair.people_money+'</td>'+
				'		<td>'+repair.royalty_money+'</td>'+
				'		<td><div class="layui-btn" onclick="xadmin.parent_add_tab(\'员工维修记录\',\'/staff/repair/index\')">员工维修记录</div></td>'+
	            '	</tr>'+
				'</tbody>';
		$('#repair-list').html(html)
	}
	/*@营业员-接口请求*/
	sale_list = function(){
		$.get("/staff/staff/sale_list",{},function(data){
			console.log(data)
			if(data.code !== 1){
				layer.msg(data.msg, {icon: 5});
				return
			}
			sale_info(data.msg);
			sale_achi(data.msg.count_order);
			sale_repair(data.msg.count_repair);
		})
	}


	sale_list()
	/*@初始化table*/
	var tableObj = table.render({
	    elem: '',
	    url: '', //数据接口
	    page: false, //开启分页
	    limits: false,
	    // where: {u_type:'新客'},
	    cols: [[ //表头
	    	{field: 'user_sn', title: '客户编号'},
	    	{title: '照片', toolbar: '<div><img src="{{d.user_img}}" width="50" height="50"></div>'},
	    	{field: 'username', title: '姓名'},
	    	{field: 'nkname', title: '称呼'},
	    	{field: 'sex', title: '性别'},
	    	{field: 'age', title: '年龄'},
	    	{field: 'phone', title: '联系方式'},
	    	{field: 'spare_phone', title: '备用联系方式'},
	    	{field: 'u_type', title: '客户类型'},
	    	{field: 'number', title: '来店次数'},
	    	{field: 'visit', title: '拜访时间'},
	    	{field: 'buy_time', title: '最近购买时间'},
	    	{title: '订单记录', width: 90, toolbar: '<div><a class="layui-btn" onclick="xadmin.open(\'订单记录\',\'/user/order/index/user_sn/{{d.user_sn}}\')">订单记录</a></div>'},
	    	{title: '咨询记录', width: 90, toolbar: '<div><a class="layui-btn" onclick="xadmin.open(\'咨询记录\',\'/user/consult/index/user_sn/{{d.user_sn}}\')">咨询记录</a></div>'},
	    	{title: '维修记录', width: 90, toolbar: '<div><a class="layui-btn" onclick="xadmin.open(\'维修记录\',\'/user/repair/index/user_sn/{{d.user_sn}}\')">维修记录</a></div>'},
	    	{title: '拜访记录', width: 90, toolbar: '<div><a class="layui-btn" onclick="xadmin.open(\'拜访记录\',\'\')">拜访记录</a></div>'},
	    	{title: '跟单记录', width: 90, toolbar: '<div><a class="layui-btn" onclick="xadmin.open(\'跟单记录\',\'\')">跟单记录</a></div>'},
	    	{title: '拜访负责人', width: 90, toolbar: '<div><a class="layui-btn" onclick="xadmin.open(\'拜访负责人\',\'\')">拜访负责人</a></div>'},
	    	{title: '跟单负责人', width: 90, toolbar: '<div><a class="layui-btn" onclick="xadmin.open(\'跟单负责人\',\'\')">跟单负责人</a></div>'},
	    	{title: '操作', width: 100,toolbar: '<div><a class="layui-btn" onclick="xadmin.open(\'查看详情\',\'/user/user/edit/ids/{{d.user_id}}\')">查看详情</a></div>'},
	    ]]
	});
	/*@查询*/
	form.on('submit(search)',function(data){

		if(data.field.start != '' && data.field.end != ''){
			var startDate = new Date(data.field.start).getTime();
			var endDate = new Date(data.field.end).getTime();
			if(startDate > endDate){
				layer.msg('开始时间不能大于结束时间',{icon: 2})
				return false
			}
		}
		/*重载表格数据*/
		tableObj.reload({
			page: {
                page: 1 //重新从第 1 页开始
            },
            where: data.field
        });
        return false
	})
});